<template>
  <div class="container">
    <navBar :navBar="navBar"></navBar>
    <div class="content">
      <div class="topInner">
        <div class="leftInner">
          <div class="image">
            <img :src="$basePath + detailInfo.img" alt="" />
          </div>
          <div class="textInner">
           <!-- <p class="text">{{ $t("获得USDT") }}</p> -->
            <p class="ttl">{{detailInfo.name}}</p>
          </div>
        </div>
        <div class="rightInner">
          <p class="text">{{ $t("近日") }}</p>
          <p class="num">{{detailInfo.rate}}%</p>
        </div>
      </div>
      <div class="textArea">
        <div class="itemArea">
          <p class="ttl">{{detailInfo.day}}({{ $t("天") }})</p>
          <p class="text">{{ $t("理财周期") }}</p>
        </div>
        <div class="itemArea">
          <p class="ttl">{{ Number(detailInfo.min)}}~9999999</p>
          <p class="text">{{ $t("单笔限额") }}({{ $t("USDT") }})</p>
        </div>
      </div>
      <div class="textSub bgBox">
        <div class="itemInner">
          <div class="item">
            <p class="text">{{ $t("派息时间") }}</p>
            <p class="note">{{ $t("每日返回") }}</p>
          </div>
		  
		  <div class="item" v-if="detailInfo.end_time">
		    <p class="text">{{ $t("截止日期") }}</p>
		    <p class="note">{{ detailInfo.end_time }}</p>
		  </div>
		  
          <div class="item">
            <p class="text">{{ $t("托管资金") }}</p>
            <p class="note">{{ $t("到期返回") }}</p>
          </div>
          <div class="item">
            <p class="text">{{ $t("提前赎回") }}</p>
            <p class="note">{{detailInfo.breach}}%</p>
          </div>
        </div>
      </div>
      <div class="textSubInner bgBox">
        <div class="itemInner">
          <div class="item">
            <p class="text">{{ $t("预计收益") }}({{ $t("USDT") }})</p>
            <p class="note">{{(Number(price) * Number(detailInfo.rate) * detailInfo.day) / 100}}</p>
          </div>
          <div class="item">
            <p class="text">{{ $t("可用资产") }}({{ $t("USDT") }})</p>
            <p class="note">{{money}}</p>
          </div>
        </div>
      </div>
      <div class="areaInner bgBox">
        <p class="title">{{ $t("投资金额") }}</p>
        <div class="inputBox">
          <input type="number" v-model="price" :placeholder="$t('请输入有效金额')" />
          <p class="text">{{ $t("USDT") }}</p>
          <p class="note" @click="getPrice">{{ $t("全部") }}</p>
        </div>
      </div>
      <div class="areaInner bgBox">
        <p class="title">{{ $t("挖矿赚不停") }}</p>
        <p class="txt">{{ detailInfo.des }}</p>
      </div>
    </div>
    <div class="button" @click="goBuy">
      <p>{{ $t("认购") }}</p>
    </div>
  </div>
</template>

<script>
import navBar from "@/components/navBar.vue";
export default {
  name: "productDetail",
  components: { navBar },
  data() {
    return {
      navBar: {
        back: true,
        title: this.$t("理财产品"),
        close: false,
        btn: "",
      },
      money: 0,
      detailInfo: {},
      price: 0,
    };
  },
  mounted () {
    this.init();
    this.getMoneyInfo();
  },
  methods: {
    // 获取可用金额
    getPrice(){
      this.price = this.money;
    },
    // 全部
    getMoneyInfo() {
		
		
      $postAxios(api.getWalletList, {}, (res) => {
		 
        if (res.code == 0) {
          res.data.forEach((item) => {
            if (item.bi_id == 1) {
              this.money = Math.floor(Number(item.money));
            }
          });
        } else {
          this.$toast(this.$t(res.msg));
        }
      });
    },
    // 认购
    goBuy() {
      if (this.price) {
        let data = {
          id: this.$route.query.id,
          money: this.price,
        };
        $postAxios(api.addMiningOrder, data, (res) => {
          if (res.code == 0) {
            this.$toast(this.$t(res.msg));
            setTimeout(() => {
              this.$router.go(-1);
            }, 600);
          } else {
            this.$toast(this.$t(res.msg));
          }
        });
      } else {
        this.$toast(this.$t("请输入有效金额"));
      }
    },
    // 初始化
    init() {
      let data = {
        id: this.$route.query.id,
		language: String(this.$i18n.locale).toUpperCase(),
      };
      $postAxios(api.getMiningInfo, data, (res) => {
        if (res.code == 0) {
          this.detailInfo = res.data;
        } else {
          this.$toast(this.$t(res.msg));
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.container {
  padding-top: 40px;
  height: 100%;
  box-sizing: border-box;
  .button {
    width: 95%;
    position: fixed;
    left: 2.5%;
    bottom: 20px;
    z-index: 10;
    color: #fff;
    font-size: 18px;
    line-height: 46px;
    text-align: center;
    border-radius: 5px;
    background-color: #24acd4;
  }
  .content {
    padding: 0 10px 70px;
    width: 100%;
    position: absolute;
    left: 0;
    top: 40px;
    bottom: 0;
    box-sizing: border-box;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background: url("../../assets/images/bg07.png") no-repeat center top;
    background-size: cover;
    .bgBox {
      margin: 0 11px 10px;
      padding: 15px;
      color: #fff;
      background-color: hsla(0, 0%, 100%, 0.2);
      .itemInner {
        display: flex;
        align-items: center;
        justify-content: space-between;
        .text {
          margin-bottom: 15px;
          color: #fff;
          font-size: 14px;
          text-align: center;
        }
        .note {
          margin-bottom: 5px;
          color: #f2c94c;
          font-weight: 700;
          font-size: 16px;
          text-align: center;
        }
      }
      .title {
        color: #fff;
        font-size: 12px;
      }
    }
    .areaInner {
      .inputBox {
        margin-top: 10px;
        display: flex;
        align-items: center;
        flex-direction: row;
        background-color: #fff;
        input {
          margin: 0 10px 0 0;
          padding: 0 10px;
          position: relative;
          z-index: 10;
          display: block;
          width: 65%;
          height: 38px;
          line-height: 38px;
          box-sizing: border-box;
          border: none;
          color: #000;
          font-size: 14px;
          background-color: #fff;
        }
        .text {
          color: #000;
          font-size: 12px;
        }
        .note {
          margin-left: 30px;
          color: #00abff;
          font-size: 15px;
        }
      }
      .txt {
        color: #fff;
        font-size: 12px;
      }
    }
    .textSub {
      margin-top: -41px;
      padding-top: 57px;
      .item {
        //width: 33.33%;
        flex-shrink: 0;
      }
    }
    .textSubInner {
      .item {
        width: 50%;
        flex-shrink: 0;
      }
    }
    .textArea {
      margin: 0 22px 10px;
      padding: 15px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      background-color: #fff;
      .itemArea {
        width: 49%;
        flex-shrink: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        flex-direction: column;
        .ttl {
          margin-bottom: 5px;
          color: #000;
          font-size: 16px;
          font-weight: 700;
        }
        .text {
          color: #000;
          font-size: 12px;
        }
      }
    }
    .topInner {
      padding: 26px 16px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      .leftInner {
        display: flex;
        align-items: center;
        .image {
          margin-right: 10px;
          width: 41px;
          flex-shrink: 0;
          img {
            width: 100%;
            height: auto;
            display: block;
          }
        }
        .textInner {
          color: #fff;
          .text {
            font-size: 12px;
          }
          .ttl {
            font-size: 16px;
          }
        }
      }
      .rightInner {
        color: #fff;
        .text {
          font-size: 12px;
        }
        .num {
          color: #f2c94c;
          font-size: 16px;
        }
      }
    }
  }
}
</style>